package cn.blnp.net.flowable.multiple.user;

import cn.hutool.core.map.MapUtil;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.filter.SimplePropertyPreFilter;
import lombok.extern.slf4j.Slf4j;
import org.assertj.core.util.Lists;
import org.flowable.engine.*;
import org.flowable.engine.repository.Deployment;
import org.flowable.engine.repository.ProcessDefinition;
import org.flowable.engine.runtime.Execution;
import org.flowable.engine.runtime.ExecutionQuery;
import org.flowable.engine.runtime.ProcessInstance;
import org.flowable.task.api.Task;
import org.flowable.task.api.TaskQuery;
import org.flowable.variable.api.persistence.entity.VariableInstance;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;

import javax.annotation.Resource;
import java.util.*;
import java.util.stream.Collectors;

/**
 * <h3>多实例演示案例-用户任务组合</h3>
 *
 * @author <a href="mailto:blnp.yibin@qq.com">lyb</a>
 * @version 1.0
 * @since 2025/5/22 14:50
 */
@Slf4j
@SpringBootTest
public class MultipleInstanceUserTaskTest {

    @Resource
    private RepositoryService repositoryService;
    @Resource
    private RuntimeService runtimeService;
    @Resource
    private TaskService taskService;
    @Resource
    private HistoryService historyService;
    @Resource
    private ManagementService managementService;

    SimplePropertyPreFilter executionFilter = new SimplePropertyPreFilter(Execution.class,
            "id", "parentId", "businessKey", "processInstanceId", "scope", "activityId");


    /**
     *  <h2>多实例概念</h2>
     *  <p>
     *   &emsp;&emsp;多实例活动用于在业务流程中定义重复环节。从开发角度讲，多实例相当于循环。可以根据给定的集合，为每个元素顺序或并行地执行某个环节，甚至某个子流程。所谓多实例，
     *   指在一个普通活动上添加额外的属性定义（称作“多实例特性”），使活动在运行时可以执行多次。需要注意的是：网关和事件不能设置为多实例。
     *  </p>
     *  <h2>父执行实例内置变量</h2>
     *  <p>
     *      <ul>
     *          <li>
     *              <b>nrOfInstances：</b>实例总数
     *          </li>
     *          <li>
     *              <b>nrOfActiveInstances：</b>当前活动的（尚未完成的）实例数量。对于串行多实例来说，这个值总是1
     *          </li>
     *          <li>
     *              <b>nrOfCompletedInstances：</b>已经完成的实例的数量
     *          </li>
     *      </ul>
     *  </p>
     *  <h2>子执行实例内置变量</h2>
     *  <p>
     *      <ul>
     *          <li>
     *              <b>loopCounter：</b>表示特定实例正在循环的索引值。
     *          </li>
     *          <li>
     *              <b></b>
     *          </li>
     *      </ul>
     *  </p>
     *
     **/
    @Test
    public void testBase() {
        
    }

    /**
     *  <h2>多实例的配置</h2>
     *  <p>
     *   &emsp;&emsp;如果一个活动被设置为多实例，则在活动底部用3条短线表示。短线的朝向表示多实例的类型：纵向表示并行多实例（并行执行），横向表示串行多实例（顺序执行）
     *   <h3>多实例类型配置</h3>
     *   &emsp;&emsp;Flowable中使用multiInstanceLoopCharacteristics的isSequential属性表示多实例的类型，isSequential= "false"表示活动是一个并行多实例，isSequential="true"表示
     *   活动是一个串行多实例。示例代码如下：
     *   <pre>
     *       {@code
     *          <multiInstanceLoopCharacteristics isSequential="false">
     *              <!-- 此处省略其他参数配置 -->
     *          </multiInstanceLoopCharacteristics>
     *       }
     *   </pre>
     *
     *   <h3>多实例的数量计算</h3>
     *   <h4>方式一：</h4>
     *   &emsp;&emsp;在进入活动时会计算一次多实例的数量，Flowable为此提供了多种配置方法。第一种配置方法是使用loopCardinality子元素指定。这种方法是使用loopCardinality子元素直接指定一个数字作为
     *   多实例的数量，格式如下：
     *   <pre>
     *       {@code
     *          <multiInstanceLoopCharacteristics isSequential="false|true">
     *              <loopCardinality>6</loopCardinality>
     *          </multiInstanceLoopCharacteristics>
     *       }
     *   </pre>
     *   使用这种方法时，也可以配置为执行结果为整数的表达式，格式如下：
     *   <pre>
     *       {@code
     *          <multiInstanceLoopCharacteristics isSequential="false|true">
     *              <loopCardinality>${nrOfOrders-nrOfCancellations}</loopCardinality>
     *          </multiInstanceLoopCharacteristics>
     *       }
     *   </pre>
     *   <h4>方式二:</h4>
     *   &emsp;&emsp;第二种配置方法是使用loopDataInputRef子元素指定。这种方法是使用loopDataInputRef子元素指定一个类型为集合的流程变量。该集合中的每个元素都会创建一个实例。另外，也可以使用inputDataItem子元
     *   素配置存储集合元素的变量名（可选）。以用户任务为例，使用这种方法的示例代码如下：
     *   <pre>
     *       {@code
     *          <userTask id="userTask1" name="多实例用户任务" flowable:assignee="${assignee}">
     *              <multiInstanceLoopCharacteristics isSequential="false">
     *                  <loopDataInputRef>assigneeList</loopDataInputRef>
     *                  <inputDataItem name="assignee" />
     *              </multiInstanceLoopCharacteristics>
     *          </userTask>
     *       }
     *   </pre>
     *   以上用户任务配置通过loopDataInputRef子元素指定了类型为集合的assigneeList流程变量，同时通过inputDataItem子元素设置assignee。假设assigneeList变量的值包括 张三、李四、王五，那么在以上配置中，
     *   3个用户任务会同时被创建（并行多实例），并且每个执行都会拥有一个名为assignee的流程变量，其包含集合中的对应元素，用于分配用户任务。使用这种方式配置多实例的数量，存在两个缺点：loopDataInputRef和
     *   inputDataItem的名称不易记忆；根据BPMN 2.0格式定义，不能包含表达式。
     *   <h4>方式三：</h4>
     *   &emsp;&emsp;通过collection和elementVariable属性指定。为了解决使用loopDataInputRef方式配置多实例数量时存在的问题，Flowable为multiInstanceCharacteristics引入了collection和elementVariable属性，
     *   其配置如下：
     *   <pre>
     *       {@code
     *          <userTask id="userTask1" name="多实例用户任务" flowable:assignee="${assignee}">
     *              <multiInstanceLoopCharacteristics isSequential="true"
     *                  flowable:collection="${myTaskUserService.getUsersOfTask()}"
     *                  flowable:elementVariable="assignee" >
     *              </multiInstanceLoopCharacteristics>
     *          </userTask>
     *       }
     *   </pre>
     *   从以上配置中可知，这里其实是使用collection属性替代了loopDataInputRef子元素，使用elementVariable属性替代了inputDataItem子元素，不同之处在于collection属性可以配置为一个表达式，使用起来更加灵活。
     *   需要注意的是，collection属性会作为表达式进行解析。如果表达式执行结果为字符串而非集合，则无论其本身配置的就是静态字符串值，还是表达式执行结果为字符串，该字符串都会被当作变量名，其值为实际的集合。示例
     *   代码如下：
     *   <pre>
     *       {@code
     *          <userTask id="userTask1" name="多实例用户任务" flowable:assignee="${assignee}">
     *              <multiInstanceLoopCharacteristics isSequential="true"
     *                  flowable:collection="assigneeList" flowable:elementVariable="assignee" >
     *              </multiInstanceLoopCharacteristics>
     *          </userTask>
     *       }
     *   </pre>
     *
     *   <h3>多实例类型配置</h3>
     *   &emsp;&emsp;Flowable默认多实例活动在所有实例都完成后才能结束。同时，Flowable提供了completionCondition子元素用于配置评估是否结束多实例的表达式，这个表达式在每个实例结束时执行一次：如果表达式计算结果为true，
     *   则当前多实例中所有剩余实例将被销毁，多实例活动结束，流程离开当前活动继续流转；如果表达式计算结果为false，则继续等待剩余实例完成。看下面的示例：
     *   <pre>
     *       {@code
     *          <userTask id="miTasks" name="多实例用户任务" flowable:assignee="${assignee}">
     *              <multiInstanceLoopCharacteristics isSequential="false"
     *                  flowable:collection="assigneeList" flowable:elementVariable="assignee" >
     *                  <completionCondition>${nrOfCompletedInstances/nrOfInstances >= 0.5 } </completionCondition>
     *              </multiInstanceLoopCharacteristics>
     *          </userTask>
     *       }
     *   </pre>
     *
     *  </p>
     *
     **/
    @Test
    public void testConfig() {

    }

    /**
     *  <h2>案例演示</h2>
     *  <p>
     *      首先，由会务人员发起流程并提交会议申请，收到会议邀请的人员现场依次签到；所有人员全部签到完成后进入投票环节，当投票完成率达到60%时结束投票。最后，会务人员根据投票结果形成决议，结束流程。
     *      <b>流程定义文件：</b>{@link flow/multiUserTaskProcess.bpmn20.xml}<br/>
     *      <b>流程预览图：</b><br/>
     *      <img src="https://cdn4.winhlb.com/2025/05/22/682ed9124d312.png" />
     *  </p>
     *  <p>
     *      <ol>
     *          <li>
     *              签到用户任务设置为串行多实例，通过flowable:collection指定该会签环节的参与人的集合。此处使用assigneeList流程变量实现。多实例在遍历assigneeList集合时把单个值保存在flowable:elementVariable指定
     *              的名为assignee的变量中，其与userTask的flowable:assignee结合使用可以决定该实例由谁进行处理；结束条件表达式配置为${nrOfCompletedInstances == nrOfInstances}，表明多实例的所有任务办理完成后才
     *              能结束多实例。
     *          </li>
     *          <li>
     *              投票用户任务设置为并行多实例。办理人集合存储在assigneeList变量中，结束条件表达式配置为${nrOfCompletedInstances/nrOfInstances >= 0.6}，表明完成总实例数的60%后结束多实例。
     *          </li>
     *      </ol>
     *  </p>
     **/
    @Test
    public void testExample() {
        Deployment deploy = repositoryService.createDeployment()
                .name("多实例实战投票-演示案例")
                .addClasspathResource("flow/multiUserTaskProcess.bpmn20.xml")
                .deploy();
        log.info("部署流程定义：{}", deploy.getId());
        ProcessDefinition procDef = repositoryService.createProcessDefinitionQuery()
                .deploymentId(deploy.getId())
                .singleResult();
        log.info("流程定义编号：{}", procDef.getId());
        //设置流程变量
        List<String> assigneeList = Lists.newArrayList("张三", "李四",
                "王五", "赵六", "安琪拉");
        //设置流程变量
        Map<String, Object> varMap1 = MapUtil.builder(new HashMap<String, Object>())
                .put("assigneeList", assigneeList)
                .build();
        //启动流程实例
        ProcessInstance procInst = runtimeService.startProcessInstanceById(procDef.getId(), varMap1);

        ExecutionQuery executionQuery = runtimeService.createExecutionQuery()
                .processInstanceId(procInst.getId());
        //查询执行实例
        List<Execution> executionList1 = executionQuery.list();
        log.info("流程发起后，执行实例数为：{}，分别为：{}", executionList1.size(),
                JSON.toJSONString(executionList1, executionFilter));
        TaskQuery taskQuery = taskService.createTaskQuery()
                .processInstanceId(procInst.getId());
        //查询第一个任务
        Task firstTask = taskQuery.singleResult();
        log.info("即将完成第一个节点的任务，当前任务taskId：{}，taskName：{}",
                firstTask.getId(), firstTask.getName());
        //完成第一个任务
        taskService.complete(firstTask.getId());
        //串行多实例用户任务，需要逐个依次办理，办理5次
        for (int i = 0; i < assigneeList.size(); i++) {
            log.info("即将办理串行多实例第{}个任务", (i + 1));
            List<Task> tasks = taskQuery.list();
            log.info("此时任务个数为：{}", tasks.size());
            log.info("当前任务taskId：{}，taskName：{}，办理人：{}", tasks.get(0).getId(),
                    tasks.get(0).getName(), tasks.get(0).getAssignee());
            //查询执行实例
            List<Execution> executionList2 = executionQuery.list();
            log.info("到达串行多实例节点后，执行实例数为：{}，分别为：{}", executionList2.size(),
                    JSON.toJSONString(executionList2, executionFilter));
            //查询流程变量
            List<Map<String, Object>> varMap2 = getAllVariables(procInst.getId());
            log.info("当前流程变量为：{}", JSON.toJSONString(varMap2));
            taskService.complete(tasks.get(0).getId());
        }
        //并行多实例用户任务，5*0.6=3个办完之后结束
        for (int i = 0; i < 3; i++) {
            log.info("办理并行多实例第{}个任务", (i + 1));
            List<Task> tasks = taskQuery.list();
            log.info("此时任务个数为：{}", tasks.size());
            log.info("当前任务taskId：{}，taskName：{}，办理人：{}", tasks.get(0).getId(),
                    tasks.get(0).getName(), tasks.get(0).getAssignee());
            //查询执行实例
            List<Execution> executionList3 = executionQuery.list();
            log.info("到达并行多实例节点后，执行实例数为：{}，分别为：{}", executionList3.size(),
                    JSON.toJSONString(executionList3, executionFilter));
            //查询流程变量
            List<Map<String, Object>> varMap3 = getAllVariables(procInst.getId());
            log.info("当前流程变量为：{}", JSON.toJSONString(varMap3));
            taskService.complete(tasks.get(0).getId());
        }
        //查询流程变量
        List<Map<String, Object>> varMap4 = getAllVariables(procInst.getId());
        log.info("当前流程变量为：{}", JSON.toJSONString(varMap4));
        //单实例用户任务
        Task task = taskQuery.singleResult();
        log.info("即将完成最后一个节点的任务，当前任务taskId：{}，taskName：{}",
                task.getId(), task.getName());
        taskService.complete(task.getId());
        //查询执行实例
        List<Execution> executionList4 = executionQuery.list();
        log.info("流程结束后，执行实例数为：{}，分别为：{}", executionList4.size(),
                JSON.toJSONString(executionList4, executionFilter));

        /**
         *  演示结果：
         *  2025-05-22 16:12:09.226  INFO 57800 --- [           main] c.b.n.f.multiple.MultipleInstanceTest    : 部署流程定义：74bdbb27-36e4-11f0-b2d3-50ebf6ec8f6d
         * 2025-05-22 16:12:09.230  INFO 57800 --- [           main] c.b.n.f.multiple.MultipleInstanceTest    : 流程定义编号：multiUserTaskProcess:1:74ffa62a-36e4-11f0-b2d3-50ebf6ec8f6d
         * 2025-05-22 16:12:09.258  INFO 57800 --- [           main] c.b.n.f.config.FlowableLoggingListener   : 流程启动 | 实例ID:750aa2af-36e4-11f0-b2d3-50ebf6ec8f6d | 定义ID:multiUserTaskProcess:1:74ffa62a-36e4-11f0-b2d3-50ebf6ec8f6d
         * 2025-05-22 16:12:09.259 DEBUG 57800 --- [           main] c.b.n.f.config.FlowableLoggingListener   : 节点进入 | 类型:startEvent | ID:startEvent1
         * 2025-05-22 16:12:09.262 DEBUG 57800 --- [           main] c.b.n.f.config.FlowableLoggingListener   : 节点进入 | 类型:userTask | ID:firstUserTask
         * 2025-05-22 16:12:09.270  INFO 57800 --- [           main] c.b.n.f.config.FlowableLoggingListener   : 任务创建 | ID:750c9e83-36e4-11f0-b2d3-50ebf6ec8f6d | 名称:会议申请 | 处理人:null
         * 2025-05-22 16:12:09.632  INFO 57800 --- [           main] c.b.n.f.multiple.MultipleInstanceTest    : 流程发起后，执行实例数为：2，分别为：[{"id":"7508f4fb-36e4-11f0-b2d3-50ebf6ec8f6d","processInstanceId":"7508f4fb-36e4-11f0-b2d3-50ebf6ec8f6d","scope":true},{"activityId":"firstUserTask","id":"750aa2af-36e4-11f0-b2d3-50ebf6ec8f6d","parentId":"7508f4fb-36e4-11f0-b2d3-50ebf6ec8f6d","processInstanceId":"7508f4fb-36e4-11f0-b2d3-50ebf6ec8f6d","scope":false}]
         * 2025-05-22 16:12:09.648  INFO 57800 --- [           main] c.b.n.f.multiple.MultipleInstanceTest    : 即将完成第一个节点的任务，当前任务taskId：750c9e83-36e4-11f0-b2d3-50ebf6ec8f6d，taskName：会议申请
         * 2025-05-22 16:12:09.670 DEBUG 57800 --- [           main] c.b.n.f.config.FlowableLoggingListener   : 节点进入 | 类型:userTask | ID:secondUserTask
         * 2025-05-22 16:12:09.679  INFO 57800 --- [           main] c.b.n.f.config.FlowableLoggingListener   : 任务创建 | ID:7549cea4-36e4-11f0-b2d3-50ebf6ec8f6d | 名称:签到 | 处理人:张三
         * 2025-05-22 16:12:09.714  INFO 57800 --- [           main] c.b.n.f.multiple.MultipleInstanceTest    : 即将办理串行多实例第1个任务
         * 2025-05-22 16:12:09.716  INFO 57800 --- [           main] c.b.n.f.multiple.MultipleInstanceTest    : 此时任务个数为：1
         * 2025-05-22 16:12:09.716  INFO 57800 --- [           main] c.b.n.f.multiple.MultipleInstanceTest    : 当前任务taskId：7549cea4-36e4-11f0-b2d3-50ebf6ec8f6d，taskName：签到，办理人：张三
         * 2025-05-22 16:12:09.717  INFO 57800 --- [           main] c.b.n.f.multiple.MultipleInstanceTest    : 到达串行多实例节点后，执行实例数为：3，分别为：[{"id":"7508f4fb-36e4-11f0-b2d3-50ebf6ec8f6d","processInstanceId":"7508f4fb-36e4-11f0-b2d3-50ebf6ec8f6d","scope":true},{"activityId":"secondUserTask","id":"7547f9dc-36e4-11f0-b2d3-50ebf6ec8f6d","parentId":"7508f4fb-36e4-11f0-b2d3-50ebf6ec8f6d","processInstanceId":"7508f4fb-36e4-11f0-b2d3-50ebf6ec8f6d","scope":false},{"activityId":"secondUserTask","id":"7549807d-36e4-11f0-b2d3-50ebf6ec8f6d","parentId":"7547f9dc-36e4-11f0-b2d3-50ebf6ec8f6d","processInstanceId":"7508f4fb-36e4-11f0-b2d3-50ebf6ec8f6d","scope":false}]
         * 2025-05-22 16:12:09.724  INFO 57800 --- [           main] c.b.n.f.multiple.MultipleInstanceTest    : 当前流程变量为：[{"processInstanceId":"7508f4fb-36e4-11f0-b2d3-50ebf6ec8f6d","executionId":"7508f4fb-36e4-11f0-b2d3-50ebf6ec8f6d","name":"assigneeList","value":["张三","李四","王五","赵六","安琪拉"]},{"processInstanceId":"7508f4fb-36e4-11f0-b2d3-50ebf6ec8f6d","executionId":"7549807d-36e4-11f0-b2d3-50ebf6ec8f6d","name":"loopCounter","value":0},{"processInstanceId":"7508f4fb-36e4-11f0-b2d3-50ebf6ec8f6d","executionId":"7547f9dc-36e4-11f0-b2d3-50ebf6ec8f6d","name":"nrOfInstances","value":5},{"processInstanceId":"7508f4fb-36e4-11f0-b2d3-50ebf6ec8f6d","executionId":"7547f9dc-36e4-11f0-b2d3-50ebf6ec8f6d","name":"nrOfCompletedInstances","value":0},{"processInstanceId":"7508f4fb-36e4-11f0-b2d3-50ebf6ec8f6d","executionId":"7547f9dc-36e4-11f0-b2d3-50ebf6ec8f6d","name":"nrOfActiveInstances","value":1},{"processInstanceId":"7508f4fb-36e4-11f0-b2d3-50ebf6ec8f6d","executionId":"7549807d-36e4-11f0-b2d3-50ebf6ec8f6d","name":"assignee","value":"张三"}]
         * 2025-05-22 16:12:09.743 DEBUG 57800 --- [           main] c.b.n.f.config.FlowableLoggingListener   : 节点进入 | 类型:userTask | ID:secondUserTask
         * 2025-05-22 16:12:09.744  INFO 57800 --- [           main] c.b.n.f.config.FlowableLoggingListener   : 任务创建 | ID:7554f245-36e4-11f0-b2d3-50ebf6ec8f6d | 名称:签到 | 处理人:李四
         * 2025-05-22 16:12:09.762  INFO 57800 --- [           main] c.b.n.f.multiple.MultipleInstanceTest    : 即将办理串行多实例第2个任务
         * 2025-05-22 16:12:09.764  INFO 57800 --- [           main] c.b.n.f.multiple.MultipleInstanceTest    : 此时任务个数为：1
         * 2025-05-22 16:12:09.764  INFO 57800 --- [           main] c.b.n.f.multiple.MultipleInstanceTest    : 当前任务taskId：7554f245-36e4-11f0-b2d3-50ebf6ec8f6d，taskName：签到，办理人：李四
         * 2025-05-22 16:12:09.767  INFO 57800 --- [           main] c.b.n.f.multiple.MultipleInstanceTest    : 到达串行多实例节点后，执行实例数为：3，分别为：[{"id":"7508f4fb-36e4-11f0-b2d3-50ebf6ec8f6d","processInstanceId":"7508f4fb-36e4-11f0-b2d3-50ebf6ec8f6d","scope":true},{"activityId":"secondUserTask","id":"7547f9dc-36e4-11f0-b2d3-50ebf6ec8f6d","parentId":"7508f4fb-36e4-11f0-b2d3-50ebf6ec8f6d","processInstanceId":"7508f4fb-36e4-11f0-b2d3-50ebf6ec8f6d","scope":false},{"activityId":"secondUserTask","id":"7549807d-36e4-11f0-b2d3-50ebf6ec8f6d","parentId":"7547f9dc-36e4-11f0-b2d3-50ebf6ec8f6d","processInstanceId":"7508f4fb-36e4-11f0-b2d3-50ebf6ec8f6d","scope":false}]
         * 2025-05-22 16:12:09.773  INFO 57800 --- [           main] c.b.n.f.multiple.MultipleInstanceTest    : 当前流程变量为：[{"processInstanceId":"7508f4fb-36e4-11f0-b2d3-50ebf6ec8f6d","executionId":"7508f4fb-36e4-11f0-b2d3-50ebf6ec8f6d","name":"assigneeList","value":["张三","李四","王五","赵六","安琪拉"]},{"processInstanceId":"7508f4fb-36e4-11f0-b2d3-50ebf6ec8f6d","executionId":"7547f9dc-36e4-11f0-b2d3-50ebf6ec8f6d","name":"nrOfInstances","value":5},{"processInstanceId":"7508f4fb-36e4-11f0-b2d3-50ebf6ec8f6d","executionId":"7547f9dc-36e4-11f0-b2d3-50ebf6ec8f6d","name":"nrOfCompletedInstances","value":1},{"processInstanceId":"7508f4fb-36e4-11f0-b2d3-50ebf6ec8f6d","executionId":"7549807d-36e4-11f0-b2d3-50ebf6ec8f6d","name":"assignee","value":"李四"},{"processInstanceId":"7508f4fb-36e4-11f0-b2d3-50ebf6ec8f6d","executionId":"7547f9dc-36e4-11f0-b2d3-50ebf6ec8f6d","name":"nrOfActiveInstances","value":1},{"processInstanceId":"7508f4fb-36e4-11f0-b2d3-50ebf6ec8f6d","executionId":"7549807d-36e4-11f0-b2d3-50ebf6ec8f6d","name":"loopCounter","value":1}]
         * 2025-05-22 16:12:09.781 DEBUG 57800 --- [           main] c.b.n.f.config.FlowableLoggingListener   : 节点进入 | 类型:userTask | ID:secondUserTask
         * 2025-05-22 16:12:09.782  INFO 57800 --- [           main] c.b.n.f.config.FlowableLoggingListener   : 任务创建 | ID:755ae5c4-36e4-11f0-b2d3-50ebf6ec8f6d | 名称:签到 | 处理人:王五
         * 2025-05-22 16:12:09.796  INFO 57800 --- [           main] c.b.n.f.multiple.MultipleInstanceTest    : 即将办理串行多实例第3个任务
         * 2025-05-22 16:12:09.797  INFO 57800 --- [           main] c.b.n.f.multiple.MultipleInstanceTest    : 此时任务个数为：1
         * 2025-05-22 16:12:09.797  INFO 57800 --- [           main] c.b.n.f.multiple.MultipleInstanceTest    : 当前任务taskId：755ae5c4-36e4-11f0-b2d3-50ebf6ec8f6d，taskName：签到，办理人：王五
         * 2025-05-22 16:12:09.800  INFO 57800 --- [           main] c.b.n.f.multiple.MultipleInstanceTest    : 到达串行多实例节点后，执行实例数为：3，分别为：[{"id":"7508f4fb-36e4-11f0-b2d3-50ebf6ec8f6d","processInstanceId":"7508f4fb-36e4-11f0-b2d3-50ebf6ec8f6d","scope":true},{"activityId":"secondUserTask","id":"7547f9dc-36e4-11f0-b2d3-50ebf6ec8f6d","parentId":"7508f4fb-36e4-11f0-b2d3-50ebf6ec8f6d","processInstanceId":"7508f4fb-36e4-11f0-b2d3-50ebf6ec8f6d","scope":false},{"activityId":"secondUserTask","id":"7549807d-36e4-11f0-b2d3-50ebf6ec8f6d","parentId":"7547f9dc-36e4-11f0-b2d3-50ebf6ec8f6d","processInstanceId":"7508f4fb-36e4-11f0-b2d3-50ebf6ec8f6d","scope":false}]
         * 2025-05-22 16:12:09.803  INFO 57800 --- [           main] c.b.n.f.multiple.MultipleInstanceTest    : 当前流程变量为：[{"processInstanceId":"7508f4fb-36e4-11f0-b2d3-50ebf6ec8f6d","executionId":"7508f4fb-36e4-11f0-b2d3-50ebf6ec8f6d","name":"assigneeList","value":["张三","李四","王五","赵六","安琪拉"]},{"processInstanceId":"7508f4fb-36e4-11f0-b2d3-50ebf6ec8f6d","executionId":"7549807d-36e4-11f0-b2d3-50ebf6ec8f6d","name":"assignee","value":"王五"},{"processInstanceId":"7508f4fb-36e4-11f0-b2d3-50ebf6ec8f6d","executionId":"7547f9dc-36e4-11f0-b2d3-50ebf6ec8f6d","name":"nrOfInstances","value":5},{"processInstanceId":"7508f4fb-36e4-11f0-b2d3-50ebf6ec8f6d","executionId":"7547f9dc-36e4-11f0-b2d3-50ebf6ec8f6d","name":"nrOfCompletedInstances","value":2},{"processInstanceId":"7508f4fb-36e4-11f0-b2d3-50ebf6ec8f6d","executionId":"7549807d-36e4-11f0-b2d3-50ebf6ec8f6d","name":"loopCounter","value":2},{"processInstanceId":"7508f4fb-36e4-11f0-b2d3-50ebf6ec8f6d","executionId":"7547f9dc-36e4-11f0-b2d3-50ebf6ec8f6d","name":"nrOfActiveInstances","value":1}]
         * 2025-05-22 16:12:09.810 DEBUG 57800 --- [           main] c.b.n.f.config.FlowableLoggingListener   : 节点进入 | 类型:userTask | ID:secondUserTask
         * 2025-05-22 16:12:09.810  INFO 57800 --- [           main] c.b.n.f.config.FlowableLoggingListener   : 任务创建 | ID:755f2b93-36e4-11f0-b2d3-50ebf6ec8f6d | 名称:签到 | 处理人:赵六
         * 2025-05-22 16:12:09.826  INFO 57800 --- [           main] c.b.n.f.multiple.MultipleInstanceTest    : 即将办理串行多实例第4个任务
         * 2025-05-22 16:12:09.828  INFO 57800 --- [           main] c.b.n.f.multiple.MultipleInstanceTest    : 此时任务个数为：1
         * 2025-05-22 16:12:09.828  INFO 57800 --- [           main] c.b.n.f.multiple.MultipleInstanceTest    : 当前任务taskId：755f2b93-36e4-11f0-b2d3-50ebf6ec8f6d，taskName：签到，办理人：赵六
         * 2025-05-22 16:12:09.830  INFO 57800 --- [           main] c.b.n.f.multiple.MultipleInstanceTest    : 到达串行多实例节点后，执行实例数为：3，分别为：[{"id":"7508f4fb-36e4-11f0-b2d3-50ebf6ec8f6d","processInstanceId":"7508f4fb-36e4-11f0-b2d3-50ebf6ec8f6d","scope":true},{"activityId":"secondUserTask","id":"7547f9dc-36e4-11f0-b2d3-50ebf6ec8f6d","parentId":"7508f4fb-36e4-11f0-b2d3-50ebf6ec8f6d","processInstanceId":"7508f4fb-36e4-11f0-b2d3-50ebf6ec8f6d","scope":false},{"activityId":"secondUserTask","id":"7549807d-36e4-11f0-b2d3-50ebf6ec8f6d","parentId":"7547f9dc-36e4-11f0-b2d3-50ebf6ec8f6d","processInstanceId":"7508f4fb-36e4-11f0-b2d3-50ebf6ec8f6d","scope":false}]
         * 2025-05-22 16:12:09.833  INFO 57800 --- [           main] c.b.n.f.multiple.MultipleInstanceTest    : 当前流程变量为：[{"processInstanceId":"7508f4fb-36e4-11f0-b2d3-50ebf6ec8f6d","executionId":"7508f4fb-36e4-11f0-b2d3-50ebf6ec8f6d","name":"assigneeList","value":["张三","李四","王五","赵六","安琪拉"]},{"processInstanceId":"7508f4fb-36e4-11f0-b2d3-50ebf6ec8f6d","executionId":"7547f9dc-36e4-11f0-b2d3-50ebf6ec8f6d","name":"nrOfInstances","value":5},{"processInstanceId":"7508f4fb-36e4-11f0-b2d3-50ebf6ec8f6d","executionId":"7547f9dc-36e4-11f0-b2d3-50ebf6ec8f6d","name":"nrOfCompletedInstances","value":3},{"processInstanceId":"7508f4fb-36e4-11f0-b2d3-50ebf6ec8f6d","executionId":"7549807d-36e4-11f0-b2d3-50ebf6ec8f6d","name":"assignee","value":"赵六"},{"processInstanceId":"7508f4fb-36e4-11f0-b2d3-50ebf6ec8f6d","executionId":"7549807d-36e4-11f0-b2d3-50ebf6ec8f6d","name":"loopCounter","value":3},{"processInstanceId":"7508f4fb-36e4-11f0-b2d3-50ebf6ec8f6d","executionId":"7547f9dc-36e4-11f0-b2d3-50ebf6ec8f6d","name":"nrOfActiveInstances","value":1}]
         * 2025-05-22 16:12:09.846 DEBUG 57800 --- [           main] c.b.n.f.config.FlowableLoggingListener   : 节点进入 | 类型:userTask | ID:secondUserTask
         * 2025-05-22 16:12:09.847  INFO 57800 --- [           main] c.b.n.f.config.FlowableLoggingListener   : 任务创建 | ID:7564a9e2-36e4-11f0-b2d3-50ebf6ec8f6d | 名称:签到 | 处理人:安琪拉
         * 2025-05-22 16:12:09.871  INFO 57800 --- [           main] c.b.n.f.multiple.MultipleInstanceTest    : 即将办理串行多实例第5个任务
         * 2025-05-22 16:12:09.874  INFO 57800 --- [           main] c.b.n.f.multiple.MultipleInstanceTest    : 此时任务个数为：1
         * 2025-05-22 16:12:09.874  INFO 57800 --- [           main] c.b.n.f.multiple.MultipleInstanceTest    : 当前任务taskId：7564a9e2-36e4-11f0-b2d3-50ebf6ec8f6d，taskName：签到，办理人：安琪拉
         * 2025-05-22 16:12:09.877  INFO 57800 --- [           main] c.b.n.f.multiple.MultipleInstanceTest    : 到达串行多实例节点后，执行实例数为：3，分别为：[{"id":"7508f4fb-36e4-11f0-b2d3-50ebf6ec8f6d","processInstanceId":"7508f4fb-36e4-11f0-b2d3-50ebf6ec8f6d","scope":true},{"activityId":"secondUserTask","id":"7547f9dc-36e4-11f0-b2d3-50ebf6ec8f6d","parentId":"7508f4fb-36e4-11f0-b2d3-50ebf6ec8f6d","processInstanceId":"7508f4fb-36e4-11f0-b2d3-50ebf6ec8f6d","scope":false},{"activityId":"secondUserTask","id":"7549807d-36e4-11f0-b2d3-50ebf6ec8f6d","parentId":"7547f9dc-36e4-11f0-b2d3-50ebf6ec8f6d","processInstanceId":"7508f4fb-36e4-11f0-b2d3-50ebf6ec8f6d","scope":false}]
         * 2025-05-22 16:12:09.886  INFO 57800 --- [           main] c.b.n.f.multiple.MultipleInstanceTest    : 当前流程变量为：[{"processInstanceId":"7508f4fb-36e4-11f0-b2d3-50ebf6ec8f6d","executionId":"7508f4fb-36e4-11f0-b2d3-50ebf6ec8f6d","name":"assigneeList","value":["张三","李四","王五","赵六","安琪拉"]},{"processInstanceId":"7508f4fb-36e4-11f0-b2d3-50ebf6ec8f6d","executionId":"7547f9dc-36e4-11f0-b2d3-50ebf6ec8f6d","name":"nrOfInstances","value":5},{"processInstanceId":"7508f4fb-36e4-11f0-b2d3-50ebf6ec8f6d","executionId":"7547f9dc-36e4-11f0-b2d3-50ebf6ec8f6d","name":"nrOfCompletedInstances","value":4},{"processInstanceId":"7508f4fb-36e4-11f0-b2d3-50ebf6ec8f6d","executionId":"7549807d-36e4-11f0-b2d3-50ebf6ec8f6d","name":"assignee","value":"安琪拉"},{"processInstanceId":"7508f4fb-36e4-11f0-b2d3-50ebf6ec8f6d","executionId":"7547f9dc-36e4-11f0-b2d3-50ebf6ec8f6d","name":"nrOfActiveInstances","value":1},{"processInstanceId":"7508f4fb-36e4-11f0-b2d3-50ebf6ec8f6d","executionId":"7549807d-36e4-11f0-b2d3-50ebf6ec8f6d","name":"loopCounter","value":4}]
         * 2025-05-22 16:12:09.920 DEBUG 57800 --- [           main] c.b.n.f.config.FlowableLoggingListener   : 节点进入 | 类型:userTask | ID:thirdUserTask
         * 2025-05-22 16:12:09.921  INFO 57800 --- [           main] c.b.n.f.config.FlowableLoggingListener   : 任务创建 | ID:756ff4a0-36e4-11f0-b2d3-50ebf6ec8f6d | 名称:投票 | 处理人:张三
         * 2025-05-22 16:12:09.922 DEBUG 57800 --- [           main] c.b.n.f.config.FlowableLoggingListener   : 节点进入 | 类型:userTask | ID:thirdUserTask
         * 2025-05-22 16:12:09.922  INFO 57800 --- [           main] c.b.n.f.config.FlowableLoggingListener   : 任务创建 | ID:757042c4-36e4-11f0-b2d3-50ebf6ec8f6d | 名称:投票 | 处理人:李四
         * 2025-05-22 16:12:09.922 DEBUG 57800 --- [           main] c.b.n.f.config.FlowableLoggingListener   : 节点进入 | 类型:userTask | ID:thirdUserTask
         * 2025-05-22 16:12:09.922  INFO 57800 --- [           main] c.b.n.f.config.FlowableLoggingListener   : 任务创建 | ID:757042c8-36e4-11f0-b2d3-50ebf6ec8f6d | 名称:投票 | 处理人:王五
         * 2025-05-22 16:12:09.922 DEBUG 57800 --- [           main] c.b.n.f.config.FlowableLoggingListener   : 节点进入 | 类型:userTask | ID:thirdUserTask
         * 2025-05-22 16:12:09.922  INFO 57800 --- [           main] c.b.n.f.config.FlowableLoggingListener   : 任务创建 | ID:757042cc-36e4-11f0-b2d3-50ebf6ec8f6d | 名称:投票 | 处理人:赵六
         * 2025-05-22 16:12:09.923 DEBUG 57800 --- [           main] c.b.n.f.config.FlowableLoggingListener   : 节点进入 | 类型:userTask | ID:thirdUserTask
         * 2025-05-22 16:12:09.923  INFO 57800 --- [           main] c.b.n.f.config.FlowableLoggingListener   : 任务创建 | ID:757069e0-36e4-11f0-b2d3-50ebf6ec8f6d | 名称:投票 | 处理人:安琪拉
         * 2025-05-22 16:12:09.987  INFO 57800 --- [           main] c.b.n.f.multiple.MultipleInstanceTest    : 办理并行多实例第1个任务
         * 2025-05-22 16:12:09.991  INFO 57800 --- [           main] c.b.n.f.multiple.MultipleInstanceTest    : 此时任务个数为：5
         * 2025-05-22 16:12:09.991  INFO 57800 --- [           main] c.b.n.f.multiple.MultipleInstanceTest    : 当前任务taskId：756ff4a0-36e4-11f0-b2d3-50ebf6ec8f6d，taskName：投票，办理人：张三
         * 2025-05-22 16:12:09.994  INFO 57800 --- [           main] c.b.n.f.multiple.MultipleInstanceTest    : 到达并行多实例节点后，执行实例数为：7，分别为：[{"id":"7508f4fb-36e4-11f0-b2d3-50ebf6ec8f6d","processInstanceId":"7508f4fb-36e4-11f0-b2d3-50ebf6ec8f6d","scope":true},{"activityId":"thirdUserTask","id":"756f3140-36e4-11f0-b2d3-50ebf6ec8f6d","parentId":"7508f4fb-36e4-11f0-b2d3-50ebf6ec8f6d","processInstanceId":"7508f4fb-36e4-11f0-b2d3-50ebf6ec8f6d","scope":false},{"activityId":"thirdUserTask","id":"756fcd84-36e4-11f0-b2d3-50ebf6ec8f6d","parentId":"756f3140-36e4-11f0-b2d3-50ebf6ec8f6d","processInstanceId":"7508f4fb-36e4-11f0-b2d3-50ebf6ec8f6d","scope":false},{"activityId":"thirdUserTask","id":"756fcd85-36e4-11f0-b2d3-50ebf6ec8f6d","parentId":"756f3140-36e4-11f0-b2d3-50ebf6ec8f6d","processInstanceId":"7508f4fb-36e4-11f0-b2d3-50ebf6ec8f6d","scope":false},{"activityId":"thirdUserTask","id":"756fcd86-36e4-11f0-b2d3-50ebf6ec8f6d","parentId":"756f3140-36e4-11f0-b2d3-50ebf6ec8f6d","processInstanceId":"7508f4fb-36e4-11f0-b2d3-50ebf6ec8f6d","scope":false},{"activityId":"thirdUserTask","id":"756fcd87-36e4-11f0-b2d3-50ebf6ec8f6d","parentId":"756f3140-36e4-11f0-b2d3-50ebf6ec8f6d","processInstanceId":"7508f4fb-36e4-11f0-b2d3-50ebf6ec8f6d","scope":false},{"activityId":"thirdUserTask","id":"756fcd88-36e4-11f0-b2d3-50ebf6ec8f6d","parentId":"756f3140-36e4-11f0-b2d3-50ebf6ec8f6d","processInstanceId":"7508f4fb-36e4-11f0-b2d3-50ebf6ec8f6d","scope":false}]
         * 2025-05-22 16:12:10.013  INFO 57800 --- [           main] c.b.n.f.multiple.MultipleInstanceTest    : 当前流程变量为：[{"processInstanceId":"7508f4fb-36e4-11f0-b2d3-50ebf6ec8f6d","executionId":"756f3140-36e4-11f0-b2d3-50ebf6ec8f6d","name":"nrOfInstances","value":5},{"processInstanceId":"7508f4fb-36e4-11f0-b2d3-50ebf6ec8f6d","executionId":"7508f4fb-36e4-11f0-b2d3-50ebf6ec8f6d","name":"assigneeList","value":["张三","李四","王五","赵六","安琪拉"]},{"processInstanceId":"7508f4fb-36e4-11f0-b2d3-50ebf6ec8f6d","executionId":"756fcd87-36e4-11f0-b2d3-50ebf6ec8f6d","name":"loopCounter","value":3},{"processInstanceId":"7508f4fb-36e4-11f0-b2d3-50ebf6ec8f6d","executionId":"756fcd85-36e4-11f0-b2d3-50ebf6ec8f6d","name":"assignee","value":"李四"},{"processInstanceId":"7508f4fb-36e4-11f0-b2d3-50ebf6ec8f6d","executionId":"756fcd87-36e4-11f0-b2d3-50ebf6ec8f6d","name":"assignee","value":"赵六"},{"processInstanceId":"7508f4fb-36e4-11f0-b2d3-50ebf6ec8f6d","executionId":"756fcd84-36e4-11f0-b2d3-50ebf6ec8f6d","name":"loopCounter","value":0},{"processInstanceId":"7508f4fb-36e4-11f0-b2d3-50ebf6ec8f6d","executionId":"756fcd84-36e4-11f0-b2d3-50ebf6ec8f6d","name":"assignee","value":"张三"},{"processInstanceId":"7508f4fb-36e4-11f0-b2d3-50ebf6ec8f6d","executionId":"756fcd88-36e4-11f0-b2d3-50ebf6ec8f6d","name":"loopCounter","value":4},{"processInstanceId":"7508f4fb-36e4-11f0-b2d3-50ebf6ec8f6d","executionId":"756f3140-36e4-11f0-b2d3-50ebf6ec8f6d","name":"nrOfCompletedInstances","value":0},{"processInstanceId":"7508f4fb-36e4-11f0-b2d3-50ebf6ec8f6d","executionId":"756fcd85-36e4-11f0-b2d3-50ebf6ec8f6d","name":"loopCounter","value":1},{"processInstanceId":"7508f4fb-36e4-11f0-b2d3-50ebf6ec8f6d","executionId":"756fcd86-36e4-11f0-b2d3-50ebf6ec8f6d","name":"loopCounter","value":2},{"processInstanceId":"7508f4fb-36e4-11f0-b2d3-50ebf6ec8f6d","executionId":"756f3140-36e4-11f0-b2d3-50ebf6ec8f6d","name":"nrOfActiveInstances","value":5},{"processInstanceId":"7508f4fb-36e4-11f0-b2d3-50ebf6ec8f6d","executionId":"756fcd88-36e4-11f0-b2d3-50ebf6ec8f6d","name":"assignee","value":"安琪拉"},{"processInstanceId":"7508f4fb-36e4-11f0-b2d3-50ebf6ec8f6d","executionId":"756fcd86-36e4-11f0-b2d3-50ebf6ec8f6d","name":"assignee","value":"王五"}]
         * 2025-05-22 16:12:10.055  INFO 57800 --- [           main] c.b.n.f.multiple.MultipleInstanceTest    : 办理并行多实例第2个任务
         * 2025-05-22 16:12:10.062  INFO 57800 --- [           main] c.b.n.f.multiple.MultipleInstanceTest    : 此时任务个数为：4
         * 2025-05-22 16:12:10.062  INFO 57800 --- [           main] c.b.n.f.multiple.MultipleInstanceTest    : 当前任务taskId：757042c4-36e4-11f0-b2d3-50ebf6ec8f6d，taskName：投票，办理人：李四
         * 2025-05-22 16:12:10.065  INFO 57800 --- [           main] c.b.n.f.multiple.MultipleInstanceTest    : 到达并行多实例节点后，执行实例数为：7，分别为：[{"id":"7508f4fb-36e4-11f0-b2d3-50ebf6ec8f6d","processInstanceId":"7508f4fb-36e4-11f0-b2d3-50ebf6ec8f6d","scope":true},{"activityId":"thirdUserTask","id":"756f3140-36e4-11f0-b2d3-50ebf6ec8f6d","parentId":"7508f4fb-36e4-11f0-b2d3-50ebf6ec8f6d","processInstanceId":"7508f4fb-36e4-11f0-b2d3-50ebf6ec8f6d","scope":false},{"activityId":"thirdUserTask","id":"756fcd84-36e4-11f0-b2d3-50ebf6ec8f6d","parentId":"756f3140-36e4-11f0-b2d3-50ebf6ec8f6d","processInstanceId":"7508f4fb-36e4-11f0-b2d3-50ebf6ec8f6d","scope":false},{"activityId":"thirdUserTask","id":"756fcd85-36e4-11f0-b2d3-50ebf6ec8f6d","parentId":"756f3140-36e4-11f0-b2d3-50ebf6ec8f6d","processInstanceId":"7508f4fb-36e4-11f0-b2d3-50ebf6ec8f6d","scope":false},{"activityId":"thirdUserTask","id":"756fcd86-36e4-11f0-b2d3-50ebf6ec8f6d","parentId":"756f3140-36e4-11f0-b2d3-50ebf6ec8f6d","processInstanceId":"7508f4fb-36e4-11f0-b2d3-50ebf6ec8f6d","scope":false},{"activityId":"thirdUserTask","id":"756fcd87-36e4-11f0-b2d3-50ebf6ec8f6d","parentId":"756f3140-36e4-11f0-b2d3-50ebf6ec8f6d","processInstanceId":"7508f4fb-36e4-11f0-b2d3-50ebf6ec8f6d","scope":false},{"activityId":"thirdUserTask","id":"756fcd88-36e4-11f0-b2d3-50ebf6ec8f6d","parentId":"756f3140-36e4-11f0-b2d3-50ebf6ec8f6d","processInstanceId":"7508f4fb-36e4-11f0-b2d3-50ebf6ec8f6d","scope":false}]
         * 2025-05-22 16:12:10.085  INFO 57800 --- [           main] c.b.n.f.multiple.MultipleInstanceTest    : 当前流程变量为：[{"processInstanceId":"7508f4fb-36e4-11f0-b2d3-50ebf6ec8f6d","executionId":"756f3140-36e4-11f0-b2d3-50ebf6ec8f6d","name":"nrOfInstances","value":5},{"processInstanceId":"7508f4fb-36e4-11f0-b2d3-50ebf6ec8f6d","executionId":"7508f4fb-36e4-11f0-b2d3-50ebf6ec8f6d","name":"assigneeList","value":["张三","李四","王五","赵六","安琪拉"]},{"processInstanceId":"7508f4fb-36e4-11f0-b2d3-50ebf6ec8f6d","executionId":"756fcd87-36e4-11f0-b2d3-50ebf6ec8f6d","name":"loopCounter","value":3},{"processInstanceId":"7508f4fb-36e4-11f0-b2d3-50ebf6ec8f6d","executionId":"756fcd85-36e4-11f0-b2d3-50ebf6ec8f6d","name":"assignee","value":"李四"},{"processInstanceId":"7508f4fb-36e4-11f0-b2d3-50ebf6ec8f6d","executionId":"756fcd87-36e4-11f0-b2d3-50ebf6ec8f6d","name":"assignee","value":"赵六"},{"processInstanceId":"7508f4fb-36e4-11f0-b2d3-50ebf6ec8f6d","executionId":"756fcd84-36e4-11f0-b2d3-50ebf6ec8f6d","name":"loopCounter","value":0},{"processInstanceId":"7508f4fb-36e4-11f0-b2d3-50ebf6ec8f6d","executionId":"756fcd84-36e4-11f0-b2d3-50ebf6ec8f6d","name":"assignee","value":"张三"},{"processInstanceId":"7508f4fb-36e4-11f0-b2d3-50ebf6ec8f6d","executionId":"756fcd88-36e4-11f0-b2d3-50ebf6ec8f6d","name":"loopCounter","value":4},{"processInstanceId":"7508f4fb-36e4-11f0-b2d3-50ebf6ec8f6d","executionId":"756f3140-36e4-11f0-b2d3-50ebf6ec8f6d","name":"nrOfCompletedInstances","value":1},{"processInstanceId":"7508f4fb-36e4-11f0-b2d3-50ebf6ec8f6d","executionId":"756fcd85-36e4-11f0-b2d3-50ebf6ec8f6d","name":"loopCounter","value":1},{"processInstanceId":"7508f4fb-36e4-11f0-b2d3-50ebf6ec8f6d","executionId":"756fcd86-36e4-11f0-b2d3-50ebf6ec8f6d","name":"loopCounter","value":2},{"processInstanceId":"7508f4fb-36e4-11f0-b2d3-50ebf6ec8f6d","executionId":"756f3140-36e4-11f0-b2d3-50ebf6ec8f6d","name":"nrOfActiveInstances","value":4},{"processInstanceId":"7508f4fb-36e4-11f0-b2d3-50ebf6ec8f6d","executionId":"756fcd88-36e4-11f0-b2d3-50ebf6ec8f6d","name":"assignee","value":"安琪拉"},{"processInstanceId":"7508f4fb-36e4-11f0-b2d3-50ebf6ec8f6d","executionId":"756fcd86-36e4-11f0-b2d3-50ebf6ec8f6d","name":"assignee","value":"王五"}]
         * 2025-05-22 16:12:10.119  INFO 57800 --- [           main] c.b.n.f.multiple.MultipleInstanceTest    : 办理并行多实例第3个任务
         * 2025-05-22 16:12:10.126  INFO 57800 --- [           main] c.b.n.f.multiple.MultipleInstanceTest    : 此时任务个数为：3
         * 2025-05-22 16:12:10.127  INFO 57800 --- [           main] c.b.n.f.multiple.MultipleInstanceTest    : 当前任务taskId：757042c8-36e4-11f0-b2d3-50ebf6ec8f6d，taskName：投票，办理人：王五
         * 2025-05-22 16:12:10.177  INFO 57800 --- [           main] c.b.n.f.multiple.MultipleInstanceTest    : 到达并行多实例节点后，执行实例数为：7，分别为：[{"id":"7508f4fb-36e4-11f0-b2d3-50ebf6ec8f6d","processInstanceId":"7508f4fb-36e4-11f0-b2d3-50ebf6ec8f6d","scope":true},{"activityId":"thirdUserTask","id":"756f3140-36e4-11f0-b2d3-50ebf6ec8f6d","parentId":"7508f4fb-36e4-11f0-b2d3-50ebf6ec8f6d","processInstanceId":"7508f4fb-36e4-11f0-b2d3-50ebf6ec8f6d","scope":false},{"activityId":"thirdUserTask","id":"756fcd84-36e4-11f0-b2d3-50ebf6ec8f6d","parentId":"756f3140-36e4-11f0-b2d3-50ebf6ec8f6d","processInstanceId":"7508f4fb-36e4-11f0-b2d3-50ebf6ec8f6d","scope":false},{"activityId":"thirdUserTask","id":"756fcd85-36e4-11f0-b2d3-50ebf6ec8f6d","parentId":"756f3140-36e4-11f0-b2d3-50ebf6ec8f6d","processInstanceId":"7508f4fb-36e4-11f0-b2d3-50ebf6ec8f6d","scope":false},{"activityId":"thirdUserTask","id":"756fcd86-36e4-11f0-b2d3-50ebf6ec8f6d","parentId":"756f3140-36e4-11f0-b2d3-50ebf6ec8f6d","processInstanceId":"7508f4fb-36e4-11f0-b2d3-50ebf6ec8f6d","scope":false},{"activityId":"thirdUserTask","id":"756fcd87-36e4-11f0-b2d3-50ebf6ec8f6d","parentId":"756f3140-36e4-11f0-b2d3-50ebf6ec8f6d","processInstanceId":"7508f4fb-36e4-11f0-b2d3-50ebf6ec8f6d","scope":false},{"activityId":"thirdUserTask","id":"756fcd88-36e4-11f0-b2d3-50ebf6ec8f6d","parentId":"756f3140-36e4-11f0-b2d3-50ebf6ec8f6d","processInstanceId":"7508f4fb-36e4-11f0-b2d3-50ebf6ec8f6d","scope":false}]
         * 2025-05-22 16:12:10.193  INFO 57800 --- [           main] c.b.n.f.multiple.MultipleInstanceTest    : 当前流程变量为：[{"processInstanceId":"7508f4fb-36e4-11f0-b2d3-50ebf6ec8f6d","executionId":"756f3140-36e4-11f0-b2d3-50ebf6ec8f6d","name":"nrOfInstances","value":5},{"processInstanceId":"7508f4fb-36e4-11f0-b2d3-50ebf6ec8f6d","executionId":"7508f4fb-36e4-11f0-b2d3-50ebf6ec8f6d","name":"assigneeList","value":["张三","李四","王五","赵六","安琪拉"]},{"processInstanceId":"7508f4fb-36e4-11f0-b2d3-50ebf6ec8f6d","executionId":"756fcd87-36e4-11f0-b2d3-50ebf6ec8f6d","name":"loopCounter","value":3},{"processInstanceId":"7508f4fb-36e4-11f0-b2d3-50ebf6ec8f6d","executionId":"756fcd85-36e4-11f0-b2d3-50ebf6ec8f6d","name":"assignee","value":"李四"},{"processInstanceId":"7508f4fb-36e4-11f0-b2d3-50ebf6ec8f6d","executionId":"756fcd87-36e4-11f0-b2d3-50ebf6ec8f6d","name":"assignee","value":"赵六"},{"processInstanceId":"7508f4fb-36e4-11f0-b2d3-50ebf6ec8f6d","executionId":"756fcd84-36e4-11f0-b2d3-50ebf6ec8f6d","name":"loopCounter","value":0},{"processInstanceId":"7508f4fb-36e4-11f0-b2d3-50ebf6ec8f6d","executionId":"756fcd84-36e4-11f0-b2d3-50ebf6ec8f6d","name":"assignee","value":"张三"},{"processInstanceId":"7508f4fb-36e4-11f0-b2d3-50ebf6ec8f6d","executionId":"756fcd88-36e4-11f0-b2d3-50ebf6ec8f6d","name":"loopCounter","value":4},{"processInstanceId":"7508f4fb-36e4-11f0-b2d3-50ebf6ec8f6d","executionId":"756f3140-36e4-11f0-b2d3-50ebf6ec8f6d","name":"nrOfCompletedInstances","value":2},{"processInstanceId":"7508f4fb-36e4-11f0-b2d3-50ebf6ec8f6d","executionId":"756fcd85-36e4-11f0-b2d3-50ebf6ec8f6d","name":"loopCounter","value":1},{"processInstanceId":"7508f4fb-36e4-11f0-b2d3-50ebf6ec8f6d","executionId":"756fcd86-36e4-11f0-b2d3-50ebf6ec8f6d","name":"loopCounter","value":2},{"processInstanceId":"7508f4fb-36e4-11f0-b2d3-50ebf6ec8f6d","executionId":"756f3140-36e4-11f0-b2d3-50ebf6ec8f6d","name":"nrOfActiveInstances","value":3},{"processInstanceId":"7508f4fb-36e4-11f0-b2d3-50ebf6ec8f6d","executionId":"756fcd88-36e4-11f0-b2d3-50ebf6ec8f6d","name":"assignee","value":"安琪拉"},{"processInstanceId":"7508f4fb-36e4-11f0-b2d3-50ebf6ec8f6d","executionId":"756fcd86-36e4-11f0-b2d3-50ebf6ec8f6d","name":"assignee","value":"王五"}]
         * 2025-05-22 16:12:10.227 DEBUG 57800 --- [           main] c.b.n.f.config.FlowableLoggingListener   : 节点进入 | 类型:userTask | ID:fourthUserTask
         * 2025-05-22 16:12:10.227  INFO 57800 --- [           main] c.b.n.f.config.FlowableLoggingListener   : 任务创建 | ID:759ecd0f-36e4-11f0-b2d3-50ebf6ec8f6d | 名称:形成决议 | 处理人:null
         * 2025-05-22 16:12:10.271  INFO 57800 --- [           main] c.b.n.f.multiple.MultipleInstanceTest    : 当前流程变量为：[{"processInstanceId":"7508f4fb-36e4-11f0-b2d3-50ebf6ec8f6d","executionId":"7508f4fb-36e4-11f0-b2d3-50ebf6ec8f6d","name":"assigneeList","value":["张三","李四","王五","赵六","安琪拉"]}]
         * 2025-05-22 16:12:10.274  INFO 57800 --- [           main] c.b.n.f.multiple.MultipleInstanceTest    : 即将完成最后一个节点的任务，当前任务taskId：759ecd0f-36e4-11f0-b2d3-50ebf6ec8f6d，taskName：形成决议
         * 2025-05-22 16:12:10.282 DEBUG 57800 --- [           main] c.b.n.f.config.FlowableLoggingListener   : 节点进入 | 类型:endEvent | ID:endEvent1
         * 2025-05-22 16:12:10.341  INFO 57800 --- [           main] c.b.n.f.multiple.MultipleInstanceTest    : 流程结束后，执行实例数为：0，分别为：[]
         **/
    }

    private List<Map<String, Object>> getAllVariables(String processInstanceId) {
        //查询所有执行实例
        List<Execution> executionList = runtimeService.createExecutionQuery()
                .processInstanceId(processInstanceId).list();
        //获取所有执行实例编号
        Set<String> executionIds = executionList.stream()
                .map(e -> e.getId()).distinct().collect(Collectors.toSet());
        //根据执行实例编号查询流程变量
        List<VariableInstance> variableInstances = runtimeService
                .getVariableInstancesByExecutionIds(executionIds);
        List<Map<String, Object>> variables = new ArrayList<>();
        for (VariableInstance variableInstance : variableInstances) {
            Map<String, Object> varMap = MapUtil.builder(new HashMap<String, Object>())
                    .put("processInstanceId", variableInstance.getProcessInstanceId())
                    .put("name", variableInstance.getName())
                    .put("value", variableInstance.getValue())
                    .put("executionId",variableInstance.getExecutionId())
                    .build();
            variables.add(varMap);
        }
        return variables;
    }
}
